package biz.obake.team.android;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class f {

    /* renamed from: a  reason: collision with root package name */
    private Resources f1540a;

    /* renamed from: b  reason: collision with root package name */
    private Bitmap f1541b;

    /* renamed from: c  reason: collision with root package name */
    private int f1542c;

    /* renamed from: d  reason: collision with root package name */
    private int f1543d;
    private Drawable e;
    private int f;
    private int g;

    public f(Resources resources, int i, int i2) {
        this.f1540a = resources;
        this.f1542c = i;
        this.f1543d = i2;
        this.f1541b = Bitmap.createBitmap(i, i2, Bitmap.Config.ARGB_8888);
    }

    private void a() {
        int i = this.f1542c;
        int i2 = this.g;
        int i3 = this.f;
        int i4 = (i * i2) / i3;
        int i5 = this.f1543d;
        if (i4 < i5) {
            i = (i3 * i5) / i2;
            i4 = i5;
        }
        int i6 = (this.f1542c / 2) - (i / 2);
        int i7 = (this.f1543d / 2) - (i4 / 2);
        this.f1541b.setDensity(this.f1540a.getDisplayMetrics().densityDpi);
        Canvas canvas = new Canvas(this.f1541b);
        this.e.setBounds(i6, i7, i + i6, i4 + i7);
        this.e.draw(canvas);
    }

    private void b() {
        int i = this.f1540a.getDisplayMetrics().densityDpi;
        if (this.f > this.f1542c || this.g > this.f1543d) {
            i = Math.min((this.f1542c * i) / this.f, (i * this.f1543d) / this.g);
        }
        this.f1541b.setDensity((i * 2) / 3);
        Canvas canvas = new Canvas(this.f1541b);
        this.e.setBounds(canvas.getClipBounds());
        this.e.draw(canvas);
    }

    public Drawable c() {
        return new BitmapDrawable(this.f1540a, this.f1541b);
    }

    public f d(Drawable drawable) {
        this.e = drawable;
        this.f = drawable.getIntrinsicWidth();
        this.g = this.e.getIntrinsicHeight();
        String simpleName = this.e.getClass().getSimpleName();
        if ("NinePatchDrawable".equals(simpleName)) {
            b();
        } else if ("BitmapDrawable".equals(simpleName)) {
            a();
        }
        return this;
    }
}
